home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14563 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  4.7 KB

  1. Path: volanj.dayton.saic.com!John_Volan
  2. From: John G. Volan <John_Volan@ccmail.dayton.saic.com>
  3. Newsgroups: comp.lang.ada,comp.lang.c++
  4. Subject: Re: some questions re. Ada/GNAT from a C++/GCC user
  5. Date: 31 Mar 1996 21:48:21 GMT
  6. Organization: Science Applications International Corp. (SAIC)
  7. Distribution: world
  8. Message-ID: <4jmuj5$lkh@dayuc.dayton.saic.com>
  9. References: <wnewmanDoxrCp.DKv@netcom.com> <SIMON.96Mar30153124@pogner.demon.co.uk> <315D902C.6F7B@escmail.orl.mmc.com> <Dp3G4u.KEA@world.std.com>
  10. NNTP-Posting-Host: volanj.dayton.saic.com
  11. Mime-Version: 1.0
  12. Content-Type: text/plain; charset=ISO-8859-1
  13. Content-Transfer-Encoding: 8bit
  14. X-Newsreader: Nuntius 2.0.3_PPC
  15. X-XXMessage-ID: <AD84565DAE011A68@volanj.dayton.saic.com>
  16. X-XXDate: Sun, 31 Mar 1996 15:33:49 GMT
  17.  
  18. In article <Dp3G4u.KEA@world.std.com> Robert A Duff, bobduff@world.std.com
  19. writes:
  20. >In article <4jhe1v$m0g@dayuc.dayton.saic.com>,
  21. >John G. Volan  <John_Volan@ccmail.dayton.saic.com> wrote:
  22. >>A C programmer would complain about having to introduce an extra
  23. >>begin/end block in order to introduce variables.  Isn't the scope
  24. >>of a variable well-defined in C, even without this extra baggage?
  25. >>It just extends from the declaration to the end of whatever block
  26. >>you're already in.
  27. >
  28. >Well, at least one Ada programmer (namely, me) would agree with the C
  29. >programmer in this case.
  30. >
  31. >>An Ada programmer would counter that, in Ada, some variables might be
  32. >>instances of _task_ types. ...
  33. >
  34. >Sorry to keep disagreeing with you, John, ...
  35.  
  36. Don't be.  Keeps things interesting! :-)
  37.  
  38. >...but this seems like the tail
  39. >wagging the dog.  If the reason I'm required to add 3 extra junk lines
  40. >of code, just to declare a simple variable, is because of tasks, then
  41. >that's just poor language design.  If you need a place to activate the
  42. >tasks, fine, put in an "Activate_Tasks_Here" statement.  Don't
  43. >complicate the job for some poor guy who has no tasks, and just wants to
  44. >declare an Integer or String variable.
  45.  
  46. Okay, maybe the tasking issue was a bit of a stretch.  With respect to
  47. tasks, I still feel that it's important to be able to distinguish the
  48. difference between elaboration and execution, but I agree that this
  49. doesn't give us a _comprehensive_ rationale for for Ada's strict rules
  50. separating declarations from statements.
  51.  
  52. Okay, then, can anybody who was in on the Ada83/Ada95 design process
  53. give us a more comprehensive rationale for this strict separation, one
  54. consequence of which being the need for declare statements?  Warning: It
  55. may not be sufficient to say that we need the blocks in order to define
  56. the scope of the declarations, since as I pointed out, it might be
  57. possible to come up with a coherent definition of the scope of a
  58. declaration even with C's scheme (C manages it somehow, after all).
  59.  
  60. One difficulty I see with intermingling declarations and statements is
  61. how to interpret declarations within conditional or iterative constructs.
  62. For instance:
  63.  
  64.     -- This is NOT Ada, this is CRAPOLA (C-Reminiscent Ada-like Perversion
  65.     -- Of Language Aspects)  :-) :
  66.     begin
  67.         ...
  68.         if Smaller then
  69.             X : Integer;
  70.             ...
  71.         elsif Bigger then
  72.             X : Long_Integer;
  73.             ...
  74.         end if;
  75.         ...
  76.         -- is X in scope here, and if so, what the heck is it?
  77.         ...
  78.         
  79.         ... loop
  80.             Y : Integer;
  81.             Get (Y);
  82.             type A is array (1 .. Y) of Integer;
  83.             package P is new Generic_P (A);
  84.             -- do these things get elaborated & destroyed every iteration?
  85.             ...
  86.         end loop ... ;
  87.         ...
  88.         -- are Y, A, and P still in scope here?
  89.     end ... ;
  90.     
  91.  
  92. I assume that the only thing that would make sense would be to treat
  93. every structured statement as the moral equivalent of a begin/end.
  94. So wherever Ada has a sequence_of_statements, CRAPOLA would have a 
  95. "block", in which statements and declarations can be intermingled,
  96. but the scope of the declarations would be limited to that "block".
  97. So the two X's above would only be in scope within their respective
  98. then-parts, and Y, A, and P would only be in scope for one iteration
  99. of the loop (i.e., they'd be created and destroyed with each iteration).
  100.  
  101. (I may not be able to follow up for a while folks, going on travel
  102. tomorrow ... hey, don't everybody cheer at once! :-)
  103.  
  104. ------------------------------------------------------------------------
  105. Internet.Usenet.Put_Signature
  106. ( Name => "John G. Volan", E_Mail => "John_Volan@dayton.saic.com",
  107.   Favorite_Slogan => "Ada95: The *FIRST* International-Standard OOPL",
  108.   Humorous_Disclaimer => "These opinions are undefined by SAIC, so" &
  109.     "any use would be erroneous ... or is that a bounded error now?" );
  110. ------------------------------------------------------------------------
  111.